<?php

namespace App\Http\Resources\Index\Chart;

use App\Http\Resources\Resource;
use Helper\Timed;

class OnlineResource extends Resource
{

    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
	    $charts = [
		    'timed' => [],
		    'data' => [
			    'online' => [],
			    'gaming' => [],
		    ],
	    ];
	    date_default_timezone_set(Timed::getTimezoneName());

	    foreach ($this->resource->toArray() as $item) {
		    $charts['timed'][] = date('H:i', $item['timed']);
		    $charts['data']['online'][] = $item['online'];
		    $charts['data']['gaming'][] = $item['gaming'];
	    }

	    return $this->getResponse()->setResponseData($charts);
    }
}
